/*
 * @Author: your name
 * @Date: 2021-04-14 10:46:45
 * @LastEditTime: 2021-04-16 17:29:49
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /flutter_demo/lib/pages/Search.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_demo/components/MyDialog.dart';
import 'package:fluttertoast/fluttertoast.dart';

class SearchPage extends StatefulWidget {
  final arguments;
  SearchPage({this.arguments});

  @override
  _SearchPageState createState() => _SearchPageState();
}

class _SearchPageState extends State<SearchPage> {
  _alertDialog() {
    print('asdasd');
    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text('确定要删除吗'),
            content: Text('删除此消息吗?'),
            actions: <Widget>[
              ElevatedButton(
                  onPressed: () {
                    print('取消');
                    Navigator.of(context).pop();
                  },
                  child: Text('取消')),
              ElevatedButton(
                  onPressed: () {
                    print('确定');
                    Navigator.of(context).pop();
                  },
                  child: Text('确定'))
            ],
          );
        });
  }

  _simpleDialog() {
    showDialog(
        context: context,
        builder: (context) {
          return SimpleDialog(
            title: Text('选择内容'),
            children: <Widget>[
              SimpleDialogOption(
                child: Text('选项A'),
                onPressed: () {
                  print('A');
                  Navigator.of(context).pop();
                  // Navigator.pop(context, 'A');
                },
              ),
              SimpleDialogOption(
                child: Text('选项B'),
                onPressed: () {
                  print('B');
                },
              ),
              SimpleDialogOption(
                child: Text('选项C'),
                onPressed: () {
                  print('C');
                },
              )
            ],
          );
        });
  }

  _bottomDialog() {
    showModalBottomSheet(
        context: context,
        builder: (context) {
          return Container(
            height: 120,
            child: Column(
              children: <Widget>[
                ListTile(
                  title: Text('share A'),
                  onTap: () {
                    print('A');
                  },
                ),
                ListTile(
                  title: Text('share B'),
                  onTap: () {
                    print('B');
                  },
                )
              ],
            ),
          );
        });
  }

  _showToast() {
    Fluttertoast.showToast(
        msg: "This is Center Short Toast",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
        backgroundColor: Colors.red,
        textColor: Colors.white,
        fontSize: 16.0);
  }

  _myDialog() {}

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('搜索'),
        ),
        body: Column(
          children: <Widget>[
            Text('${widget.arguments != null ? widget.arguments["id"] : "0"}'),
            ElevatedButton(
                onPressed: _alertDialog, child: Text('alert dialog')),
            ElevatedButton(
                onPressed: _simpleDialog, child: Text('simple dialog')),
            ElevatedButton(
                onPressed: _bottomDialog, child: Text('bottom dialog')),
            ElevatedButton(onPressed: _showToast, child: Text('toast')),
            ElevatedButton(
                onPressed: () {
                  showDialog(
                      context: context,
                      builder: (context) {
                        return MyDialog(title: '自定义标题', content: '我是自定义弹框');
                      });
                },
                child: Text('自定义dialog'))
          ],
        ));
  }
}
